import { ChainProvider, EvmProvider, XrpProvider } from "./ChainProvider";
import { BridgeConfig } from "./BridgeConfig";

export enum BridgeDirection {
    EVM_TO_XRP,
    XRP_TO_EVM,
}

export function createProviders(direction: BridgeDirection, config: BridgeConfig): ProvidersType {
    const xrpProvider = new XrpProvider(config);
    const evmProvider = new EvmProvider(config);
    return {
        [BridgeDirection.XRP_TO_EVM]: {
            source: xrpProvider,
            destination: evmProvider,
        },
        [BridgeDirection.EVM_TO_XRP]: {
            source: evmProvider,
            destination: xrpProvider,
        },
    };
}

export async function initProviders(providers: ProvidersType): Promise<void> {
    await Promise.all([providers[BridgeDirection.XRP_TO_EVM].source.init(), providers[BridgeDirection.XRP_TO_EVM].destination.init()]);
}

export type ProvidersType = Record<BridgeDirection, { source: ChainProvider; destination: ChainProvider }>;
